<%--
  Created by IntelliJ IDEA.
  User: 70481
  Date: 2019/9/6
  Time: 12:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>科室信息</title>
    <link href="layui/css/layui.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="js/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="layui/layui.js"></script>

    <script>
        layui.use(['table','form','layer'],function(){
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;
            <%--alert(${param.departmentId})--%>
            // 初始化表格
            table.render({
                elem: '#myTable'
                ,url: 'selectTriageInfo' //数据接口
                ,page: true //开启分页
                ,toolbar:"#myDiv"
                ,where:{"departmentId":${param.departmentId}}
                ,defaultToolbar:[]
                ,cols: [[ //表头
                    {checkbox:"checkbox"},
                    {field: 'dotTriageId', title: '编号'}
                    ,{field: 'dtoPatientName', title: '患者'}
                    ,{field: 'dtoPatientSex', title: '性别',templet:"#titleTpl"}
                    ,{field: 'dtoPatientBirth', title: '出生年月'}
                    ,{field: 'dtoTriageStatus', title: '诊断状态',templet:"#status"}
                    ,{toolbar:"#myToolbar", title: '操作'}
                ]]
            })
            // toolbar监听

            table.on("tool(myTable)",function (obj) {
                // 获取点击的按钮的avent和当前的行数据

                var params = obj.data;
                var event = obj.event;
                // alert(event)
                // console.log(params)
                if(event === "update"){
                    // 修改操作
                    add()
                    form.val("myDepartment",{
                        triageId:params.dotTriageId,
                        dtoPatientId:params.dtoPatientId,
                        dtoPatientName:params.dtoPatientName,
                        dtoDepartmentId:params.dtoDepartmentId,
                        dtoDepartmentName:params.dtoDepartmentName,
                        userId:"${sessionScope.user.userId}",
                        dtoUserName:"${sessionScope.user.userName}",
                        triageIllnessInfo:params.dtoTriageIllnessInfo,
                        triageAdvice:params.dtoTriageAdvice
                    })
                }

              /*  if (event === "delete"){
                    // 删除操作
                    $.ajax({
                        url:"deleteDepartment",
                        data:{"departmentId":params.departmentId},
                        success:function(data){
                            layer.alert(data.isDelete,{time:1250})
                            layer.closeAll("page");
                            table.reload("myTable");
                        }
                    })
                }*/
            })


            // form表单提交

            form.on("submit(formDemo)",function (data) {
                var params = data.field;
                    // 修改操作
                    $.ajax({
                        url:"updateTriage",
                        type:"post",
                        data:params,
                        success:function (data) {
                            layer.alert(data.isUpdate,{time:1250});
                            layer.closeAll("page");
                            table.reload("myTable");
                        }
                    })
                return false;
            })
        });

        // 模糊查询
        function vague() {
            // 获取输入框中的内容
            var param = $("#vague").val();
            // alert(param)
            var table = layui.table;
            // 表单重载
            table.reload("myTable",{
                where:{"name":param}
            })
        }

        function add() {
            // 弹出表单
            var layer = layui.layer;
            // 表单内容重置
            $("#myDepartment")[0].reset();
            layer.open({
                type: 1,
                offset: "t",
                anim: 1,
                area:'600px',
                content: $("#myDepartment")
            })
        }

        // 批量删除

        function multiDelete() {
            // 获取所有被选中的数据
            // alert(12123)
            var table = layui.table;
            var layer = layui.layer;
            var params = table.checkStatus("myTable");
             console.log(params)
            var array = new Array(params.data.length)
            for(var i = 0;i < params.data.length;i++){
                array[i] = params.data[i].departmentId;
            }
            console.log(array)
            // 批量删除的ajax
            $.ajax({
                url:"",
                data:{"array":array},
                traditional:true,
                success:function (data) {
                    layer.alert(data.isDelete,{time:1250});
                    table.reload("myTable");
                }
            })
        }
    </script>
    <script type="text/html" id="titleTpl">
        {{#  if(d.dtoPatientSex ==1){ }}
        (男)
        {{#  } else { }}
        (女)
        {{#  } }}
    </script>

    <script type="text/html" id="status">
        {{#  if(d.dtoTriageStatus ==0){ }}
        等待诊断
        {{#  } else if(d.dtoTriageStatus ==1){ }}
        诊断中
        {{#  }else{ }}
        诊断结束
        {{#  } }}
    </script>
</head>
<body>
<table id="myTable" lay-filter = "myTable"></table>
<%--toolbar  自定义的工具栏模板--%>
<script type="text/html" id="myToolbar">
        <button type="button" class="layui-btn layui-btn-radius layui-btn-warm layui-btn-sm" lay-event="update" id="update">诊断</button>
</script>

<%--行内菜单  用于table的表头--%>
    <div id="myDiv" style="display: none">
        <button type="button" class="layui-btn layui-btn-radius layui-btn-warm layui-btn-sm" lay-event="update" id="add" onclick="add()">
            <i class="layui-icon layui-icon-add-circle"></i>添加</button>
        <button type="button" class="layui-btn layui-btn-radius layui-btn-danger layui-btn-sm" lay-event="delete" id="multiDele" onclick="multiDelete()">
            <i class="layui-icon layui-icon-delete"></i>批量删除</button>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="text" name="name"  id="vague" placeholder="请输入要查询的科室名称">
        <button  class="layui-btn layui-btn-radius layui-btn-primary layui-btn-xs" lay-filter="sub" >
            <i class="layui-icon layui-icon-search"  onclick="vague()">搜索</i>
        </button>
    </div>


<%--弹出层--%>
    <form class="layui-form" action="" style="display: none" id="myDepartment" lay-filter="myDepartment">
    <input type="hidden" name="triageId">
    <div class="layui-form-item">
        <label class="layui-form-label">患者编号</label>
        <div class="layui-input-block">
            <input type="text" name="dtoPatientId" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">患者姓名</label>
        <div class="layui-input-block">
            <input type="text" name="dtoPatientName" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">科室编号</label>
        <div class="layui-input-block">
            <input type="text" name="dtoDepartmentId" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">科室</label>
        <div class="layui-input-block">
            <input type="text" name="dtoDepartmentName" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">医生编号</label>
        <div class="layui-input-block">
            <input type="text" name="userId" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">医生姓名</label>
        <div class="layui-input-block">
            <input type="text" name="dtoUserName" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">病症描述</label>
        <div class="layui-input-block">
            <textarea name="triageIllnessInfo" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">病症意见</label>
        <div class="layui-input-block">
            <textarea name="triageAdvice" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

</body>
</html>
